import walf
import funksvd
import pandas as pd
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import os
import numpy as np
from getFuncton import get_train


x=[]
y=[]
n=10
z = np.arange(0, n)
data=pd.read_csv("ratings.csv",sep="\s+")
# data_=pd.read_csv("output.csv")
i=0
while i<n:
        all = get_train(data)
        train = all[0]
        test = all[1]

        x.append(walf.walf(train,test,0.2))
        y.append(funksvd.funksvd(train,test))
        i=i+1




# 保存loss文件
com={'wmf':x,'funsvd':y,'com':[x - y for x, y in zip(x, y)]}
df = pd.DataFrame(com)
df.to_csv("com.csv")

# 柱状图
plt.bar(z-0.15, x, color='blue', width=0.3, align='center', label='y')
plt.bar(z+0.15, y, color='green', width=0.3, align='center', label='z')
print([x - y for x, y in zip(x, y)])
filename = os.path.expanduser("comp3")
plt.savefig(filename)
plt.show()
